﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace WinGameControls
{
    internal partial class MessageDialog : Form
    {
        internal MessageDialog (Icon boxIcon, string message, string caption, MessageBoxButtons buttons)
        {
            InitializeComponent();
            Text = caption;
            messageText.Text = message;

            this.ControlBox = this.ShowIcon = boxIcon != null;
            if (boxIcon != null)
                this.Icon = boxIcon;

            var lastPos = messageText.Text.Length == 0?
                new Point() : messageText.GetPositionFromCharIndex (messageText.Text.Length-1);

            if (lastPos.Y > 0)
            {
                messageText.TextAlign = HorizontalAlignment.Left;
                this.Size = new Size (Size.Width, Size.Height + lastPos.Y);
                messageText.Size = new Size (messageText.Width, messageText.Height + lastPos.Y);
            }

            if (buttons == MessageBoxButtons.OK)
            {
                button1.Visible = false;
                button2.Text = "O&K";
                button2.DialogResult = DialogResult.OK;
                this.AcceptButton = button2;
                this.CancelButton = button2;
            }
            else if (buttons == MessageBoxButtons.YesNo)
            {
                button1.Text = "&Yes";
                button2.Text = "&No";
                button1.DialogResult = DialogResult.Yes;
                button2.DialogResult = DialogResult.No;
                this.AcceptButton = button1;
                this.CancelButton = button2;
            }
            else
                throw new NotSupportedException ("Dialog type unimplemented");
        }
    }
}
